home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / prtinfo / prtinfo.frm < prev    next >
Text File  |  1995-05-08  |  2KB  |  88 lines

  1. VERSION 2.00
  2. Begin Form Form1 
  3.    Caption         =   "Device name and port"
  4.    ClientHeight    =   975
  5.    ClientLeft      =   1080
  6.    ClientTop       =   1650
  7.    ClientWidth     =   7485
  8.    Height          =   1380
  9.    Left            =   1020
  10.    LinkTopic       =   "Form1"
  11.    ScaleHeight     =   975
  12.    ScaleWidth      =   7485
  13.    Top             =   1305
  14.    Width           =   7605
  15.    Begin Label Label1 
  16.       AutoSize        =   -1  'True
  17.       Caption         =   "Label1"
  18.       Height          =   195
  19.       Left            =   360
  20.       TabIndex        =   0
  21.       Top             =   300
  22.       Width           =   585
  23.    End
  24. End
  25.  
  26.  
  27.  
  28.    
  29.  
  30. '... This function converts a windows API LPstring to a VB string.
  31. '
  32. Function FixAPIString$ (ByVal test$)
  33.  
  34.   FixAPIString$ = Trim(Left$(test$, InStr(test$, Chr$(0)) - 1))
  35.  
  36. End Function
  37.  
  38. Sub Form_Load ()
  39.  
  40.   Dim dev$, devname$, devoutput$
  41.   dev$ = GetDefPrinter$() ' Get default printer info
  42.   If dev$ = "" Then GoTo jump1
  43.   devname$ = GetDeviceName$(dev$)' Strip the device name from dev$
  44.   devoutput$ = GetDeviceOutput$(dev$)' Strip the device port from dev$
  45.   label1.Caption = devname$ + " on  " + devoutput$
  46.   GoTo jump2
  47. jump1:
  48.   label1.Caption = "No device found"
  49. jump2:
  50.  
  51. End Sub
  52.  
  53. '  This function retrieves the definition of the default
  54. '  printer on this system contained in the win.ini file.
  55. '
  56. Function GetDefPrinter$ ()
  57.  
  58.     Dim def$
  59.     def$ = String$(128, 0)
  60.     di% = GetProfileString%("windows", "device", "", def$, Len(def$))
  61.     def$ = FixAPIString$(def$)
  62.     GetDefPrinter$ = def$
  63.     
  64. End Function
  65.  
  66. '   Retrieves the name portion of a device string.
  67. '
  68. Function GetDeviceName$ (dev$)
  69.  
  70.     Dim npos%
  71.     npos% = InStr(dev$, ",")
  72.     GetDeviceName$ = Left$(dev$, npos% - 1)
  73.  
  74. End Function
  75.  
  76. '   Returns the output destination for the specified
  77. '   device.
  78. '
  79. Function GetDeviceOutput$ (dev$)
  80.  
  81.     Dim firstpos%, nextpos%
  82.     firstpos% = InStr(dev$, ",")
  83.     nextpos% = InStr(firstpos% + 1, dev$, ",")
  84.     GetDeviceOutput$ = Mid$(dev$, nextpos% + 1)
  85.  
  86. End Function
  87.  
  88.